#include <bits/stdc++.h>
// 2025/05/17
// tag: LCA
// Author: Forever
using namespace std;
using int64 = int64_t;

#define MAXN 500001
#define LOG_MAX 20

int n, m, s;
vector<int> tree[MAXN];

int up[MAXN][LOG_MAX];
int depth[MAXN];

void preprocess(int u, int parent)
{
    up[u][0] = parent;
    for (int k = 1; k < LOG_MAX; ++k) {
        up[u][k] = up[up[u][k - 1]][k - 1];
    }
    for (int v : tree[u]) {
        if (v != parent) {
            depth[v] = depth[u] + 1;
            preprocess(v, u);
        }
    }
}

int lca(int u, int v)
{
    if (depth[u] < depth[v])
        swap(u, v);
    for (int k = LOG_MAX - 1; k >= 0; --k) {
        if (depth[u] - (1 << k) >= depth[v]) {
            u = up[u][k];
        }
    }
    if (u == v)
        return u;
    for (int k = LOG_MAX - 1; k >= 0; --k) {
        if (up[u][k] != up[v][k]) {
            u = up[u][k];
            v = up[v][k];
        }
    }
    return up[u][0];
}

int main()
{
    cin >> n >> m >> s;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    preprocess(s, s);
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        int l = lca(u, v);
        cout << l << endl;
    }
    return 0;
}